{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 5: Fractionally Differentiated Features\n",
    "___\n",
    "\n",
    "## Exercises\n",
    "\n",
    "**5.1** Generate a time series from an IID Gaussian random process. This is a memoryless, stationary series:\n",
    "- **(a)** Compute the ADF statistic on this series. What is the p-value?\n",
    "- **(b)** Compute the cumulative sum of the observations. This is a non-stationary series without memory.\n",
    " - **(i)** What is the order of integration of this cumulative series?\n",
    " - **(ii)** Compute the ADF statistic on this series. What is the p-value?\n",
    "- **(c)** Differentiate the series twice. What is the p-value of this over-differentiated series?\n",
    "\n",
    "**5.2** Generate a time series that follows a sinusoidal function. This is a stationary series with memory.\n",
    "- **(a)** Compute the ADF statistic on this series. What is the p-value?\n",
    "- **(b)** Shift every observation by the same positive value. Compute the cumulative sum of the observations. This is a non-stationary series with memory.\n",
    " - **(i)** Compute the ADF statistic on this series. What is the p-value?\n",
    " - **(ii)** Apply an expanding window fracdiff, with  $\\tau= 1e-2$. For what minimum d value do you get a p-value below 5%?\n",
    " - **(iii)** Apply FFD, with $\\tau= 1e-5$. For what minimum d value do you get a p-value below 5%?\n",
    "\n",
    "**5.3** Take the series from exercise 2.b:\n",
    "- **(a)** Fit the series to a sine function. What is the R-squared?\n",
    "- **(b)** Apply FFD(d=1). Fit the series to a sine function. What is the R-squared?\n",
    "- **(c)** What value of d maximizes the R-squared of a sinusoidal fit on FFD(d). Why?\n",
    "\n",
    "**5.4** Take the dollar bar series on E-mini S&P 500 futures. Using the code in Snippet 5.3, for some $d \\in [0, 2]$, compute *fracDiff_FFD(fracDiff_FFD(series,d),-d)*. What do you get? Why?\n",
    "\n",
    "**5.5** Take the dollar bar series on E-mini S&P 500 futures.\n",
    "- **(a)** Form a new series as a cumulative sum of log-prices.\n",
    "- **(b)** Apply FFD, with $\\tau= 1e-5$. Determine for what minimum $d \\in [0, 2]$, the new series is stationary.\n",
    "- **(c)** Compute the correlation of the fracdiff series to the original (untransformed) series.\n",
    "- **(d)** Apply an Engel-Granger cointegration test on the original and fracdiff series. Are they cointegrated? Why?\n",
    "- **(e)** Apply a Jarque-Bera normality test on the fracdiff series.\n",
    "\n",
    "5.6 Take the fracdiff series from exercise 5.\n",
    "- **(a)** Apply a CUSUM filter (Chapter 2), where h is twice the standard deviation of the series.\n",
    "- **(b)** Use the filtered timestamps to sample a features’ matrix. Use as one of the features the fracdiff value.\n",
    "- **(c)** Form labels using the triple-barrier method, with symmetric horizontal barriers of twice the daily standard deviation, and a vertical barrier of 5 days.\n",
    " - **(d)** Fit a bagging classifier of decision trees where:\n",
    " - **(i)** The observed features are bootstrapped using the sequential method from Chapter 4.\n",
    " - **(ii)** On each bootstrapped sample, sample weights are determined using the techniques from Chapter 4.\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
